package org.e_gold.dao.impl;

import java.util.List;

import org.e_gold.dao.CookieDAO;
import org.e_gold.model.Cookie;
import org.e_gold.util.BrowserTypeENUM;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public class CookieDAOImpl extends AbstractGenericDAO<Cookie> implements CookieDAO {

    public CookieDAOImpl() {

        super(Cookie.class);
    }

    @Override
    @Transactional
    public Cookie findCookieByName(String key, String browserType) {

        return (Cookie) getCurrentSession()
                .getNamedQuery("findCookieByName")
                .setString("name", key)
                .setString("browserType", browserType == null ? BrowserTypeENUM.FIREFOX_VERSION.toString() : browserType)
                .uniqueResult();
    }

    @SuppressWarnings("unchecked")
    @Override
    @Transactional
    public List<Cookie> findAll(String browserType) {

        return getCurrentSession()
                .getNamedQuery("findCookieByBrowserType")
                .setString("browserType", browserType)
                .list();
    }

}
